;(function(a) {
    a.fn.gotop = function(c) {
        var d = a.extend({
            content: 960,
            bottom: 30,
            margin: "none",
            position: "right",
            scrollTop: 100,
            duration: 700
        }, c);
        var g = a(window);
        var f = this;
        function h() {
            var i = true;
            if (d.margin == "none") {
                if (g.width() < (d.content + (f.width() * 2) + 4)) {
                    i = false
                }
            } else {
                if (g.width() < (d.content + ((f.width() + d.right) * 2) + 4)) {
                    i = false
                }
            }
            return i
        }
        function b() {
            var i = (((g.width() - d.content) / 2) - f.width()) / 2;
            if (d.position == "left" || d.position == "l") {
                f.css({
                    left: i + "px"
                })
            } else {
                f.css({
                    right: i + "px"
                })
            }
        }
        function e() {
            if (g.scrollTop() > d.scrollTop) {
                f.fadeIn()
            } else {
                f.fadeOut()
            }
        }
        if (!h()) {
            this.hide()
        }
        if (d.margin == "none") {
            b()
        } else {
            if (d.position == "left" || d.position == "l") {
                f.css({
                    left: d.margin + "px"
                })
            } else {
                f.css({
                    right: d.margin + "px"
                })
            }
        }
        e();
        g.resize(function() {
            if (h()) {
                f.fadeIn()
            } else {
                f.fadeOut()
            }
            if (d.margin == "none") {
                b()
            }
        });
        g.scroll(function() {
            e()
        });
        return this.css({
            position: "fixed",
            cursor: "pointer",
            bottom: d.bottom + "px"
        }).click(function() {
            a("body,html").animate({
                scrollTop: 0
            }, d.duration)
        })
    }
}
)(jQuery);
;;var footerPage = _ns.genNameSpace("ns.footerPage");
(function(ns) {
    ns.run = function() {
        ns.bindGoTop();
        ns.hideBanner();
        _util.domainCheck();
    }
    ns.bindGoTop = function() {
        $('.go_top').gotop({
            content: 240,
            bottom: 30,
            margin: "none",
            position: "right",
            scrollTop: 100,
            duration: 400
        });
    }
    ns.hideBanner = function() {
        $('.anye_down_box').addClass(window.sessionStorage.getItem('bannerDown'));
        $(".anye_down_box .close").click(function() {
            $(".anye_down_box").addClass("hidden");
            window.sessionStorage.setItem('bannerDown', 'hidden');
        });
    }
    ns.run();
}
)(footerPage);
$(function() {
    $.ajaxRequest = function(url, data, method, callback) {
        typeof method == 'undefined' ? method = 'get' : "'"
        typeof data == 'undefined' ? data = {} : ""
        $.ajax({
            method: method,
            url: url,
            data: data,
            dataType: 'json',
            success: function(data) {
                if (typeof callback == 'undefined') {} else {
                    callback(data);
                }
            }
        });
    }
    $.ajaxRequestStat = function(type) {
        if (type == '')
            return false;
        $.ajaxRequest('/stat-stat', {
            'type': type
        }, 'post')
    }
    $.ajaxRequestFirstIndex = function() {
        $.ajaxRequest('/index-index_first', {}, 'post', function(e) {
            if (e.status == 1) {
                $('.read_first').removeClass('hidden')
            }
        })
    }
});
;var bookReadPage = _ns.genNameSpace("ns.bookReadPage");
(function(ns) {
    ns.run = function() {
        ns.pageInit();
        ns.jqueryPageInit();
        ns.bgColorInit();
        ns.bindCatelog();
        ns.bindDashang();
        ns.bindAddShelfInit();
        ns.bindDoSub();
        ns.bindGoTop();
        _util.disablePageCopy();
    }
    ns.ModalHelper = (function(bodyCls) {
        var scrollTop;
        var rootElement = document.scrollingElement || document.body;
        return {
            afterOpen: function() {
                scrollTop = rootElement.scrollTop;
                document.body.classList.add(bodyCls);
                document.body.style.top = -scrollTop + 'px';
            },
            beforeClose: function() {
                document.body.classList.remove(bodyCls);
                rootElement.scrollTop = scrollTop;
            }
        };
    }
    )('top_distance');
    ns.bindGoTop = function() {
        $('.go_top').gotop({
            content: 240,
            bottom: 60,
            margin: "none",
            position: "right",
            scrollTop: 100,
            duration: 400
        });
    }
    ns.pageInit = function() {
        ns.articleId = parseInt($('#article_id').val() || 0);
        ns.userId = parseInt($('#userid').val() || 0);
    }
    ns.bgColorInit = function() {
        var bgColor = window.localStorage.getItem('bgColor') || '';
        ns.setBgColor(bgColor);
        $(".read_night").click(function() {
            if ($(".reading").hasClass("night")) {
                ns.setBgColor('');
            } else {
                ns.setBgColor('night');
            }
        })
    }
    ns.setBgColor = function(set) {
        var set = set || '';
        if (set == "night") {
            $(".read_night").find("p").html("日间");
            $(".read_night").find("img").attr("src", _util.config.url.mcdn + "/images/read_day.png");
            $(".reading").addClass("night");
            $(".font_setbox").addClass("hidden");
            window.localStorage.setItem('bgColor', 'night');
        } else {
            $(".read_night").find("p").html("夜间");
            $(".read_night").find("img").attr("src", _util.config.url.mcdn + "/images/read_night.png");
            $(".reading").removeClass("night");
            $(".font_setbox").addClass("hidden");
            window.localStorage.setItem('bgColor', '');
        }
    }
    ns.bindDoSub = function() {
        $('#do-sub-btn').click(function(e) {
            $('#sub-form').submit();
        })
    }
    ns.bindCatelog = function() {
        $('.chapter-btn').click(function(e) {
            var btn = $(this);
            var current = parseInt(btn.attr('data-current') || 0);
            var liList = $('.book_catelog li').toArray();
            if (!current)
                liList.reverse();
            btn.siblings('a').attr('data-current', 0).removeClass('act')
            btn.attr('data-current', 1).addClass('act');
            $('.book_catelog').html(liList);
        });
    }
    ns.bindDashang = function() {
        $('.gift_box').find('.img_box').click(function(e) {
            var dashangItem = $(this);
            var remain = Number(dashangItem.attr('data-remain'))
            $('.gift_box').find('.img_box').removeClass('act');
            $(this).addClass('act');
            $('#give_num').val('1');
            $('#give_name').html(dashangItem.attr('data-title'));
            $('#give_money').html(dashangItem.attr('data-price'));
            $('#give_desc').val(dashangItem.attr('data-desc'));
            $('a.reward').attr({
                'data-itemid': dashangItem.attr('data-id'),
                'data-bonus': dashangItem.attr('data-price'),
            });
            if (remain < parseInt(dashangItem.attr('data-price'))) {
                $('a.reward').text("余额不足，请先充值");
                $('a.reward').attr('href', '/pay');
            } else {
                $('a.reward').text("捧场");
                $('a.reward').attr('href', 'javascript:;');
            }
        });
        $('#give_num').change(function(e) {
            var val = parseInt($(this).val());
            var bonus = parseInt($('a.reward').attr('data-bonus')) || 200;
            $('#give_money').html(val * bonus);
        });
        var submitRewardForm = function(e) {
            var btn = $(this);
            var num = parseInt($('#give_num').val()) || 1;
            var itemid = parseInt(btn.attr('data-itemid')) || 1;
            var articleid = ns.articleId;
            var bonus = parseInt(btn.attr('data-bonus')) || 200;
            var comment = $('#give_desc').val() || '';
            var data = {
                articleid: articleid,
                bonus: bonus,
                comment: comment,
                num: num,
                itemid: itemid
            };
            if (!check_user_bind()) {
                return false;
            }
            $('a.reward').unbind('click');
            $.ajax({
                url: _util.config.url.dynamic + "/reward-reward_money",
                data: data,
                dataType: "jsonp",
                success: function(e) {
                    if (e.status == 200) {
                        $('.mask').addClass('hidden');
                        $('.giftbg').addClass('hidden');
                        $('.add_shelf_alert').removeClass('hidden');
                        $('.add_shelf_alert').html("恭喜你打赏成功");
                        setTimeout(function() {
                            $('.add_shelf_alert').addClass('hidden');
                        }, 2000);
                        $('a.reward').click(submitRewardForm);
                    }
                },
                error: function(e) {
                    $('a.reward').click(submitRewardForm);
                },
                complete: function(e) {
                    ns.ModalHelper.beforeClose();
                }
            });
        };
        $('a.reward').click(submitRewardForm);
    }
    ns.bindAddShelfInit = function() {
        var addShelfAction = function(favorSet) {
            var articleid = ns.articleId;
            $.ajax({
                url: _util.config.url.dynamic + "/favor-favorite_book",
                data: {
                    articleid: articleid,
                    favor: favorSet
                },
                dataType: "jsonp",
                success: function(e) {
                    if (200 == e.status) {
                        if (e.favor == 1) {
                            $('.add_shelf_alert').html("添加至书架成功");
                            $('.add_shelf_alert').removeClass('hidden');
                        } else {
                            $('.add_shelf_alert').html("已取消收藏");
                            $('.add_shelf_alert').removeClass('hidden');
                        }
                        setTimeout(function() {
                            $('.add_shelf_alert').addClass('hidden');
                        }, 2000);
                    } else if (301 == e.status) {
                        location.href = e.msg;
                    }
                }
            });
        }
        $(".alert .confirm").click(function(e) {
            $(".top-alert").addClass("hidden");
            var favorSet = 1;
            addShelfAction(favorSet);
        })
        $(".confirm2").click(function(e) {
            $(".top-alert").addClass("hidden");
            var favorSet = 1;
            addShelfAction(favorSet);
        })
        $(".alert .close").click(function(e) {
            $(".top-alert").addClass("hidden");
        })
    }
    ns.jqueryPageInit = function() {
        $(".mask").click(function() {
            $('.mask').addClass('hidden');
            $('.giftbg').addClass('hidden');
            $('.read_cont_box').addClass('hidden');
            $(".font_setbox").addClass("hidden");
        })
        $(".read_font").click(function() {
            if ($(".font_setbox").hasClass("hidden")) {
                $(".font_setbox").removeClass("hidden");
            } else {
                $(".font_setbox").addClass("hidden");
            }
        });
        var textFontSize = +window.localStorage.getItem('textFontSize') || 18;
        var titleFontSize = +window.localStorage.getItem('titleFontSize') || 20;
        var textLineHeight = +window.localStorage.getItem('textLineHeight') || 32;
        var textIndent = +window.localStorage.getItem('textIndent') || 36;
        $(".page_content").css("font-size", textFontSize + "px");
        $(".page_title").css("font-size", titleFontSize + "px");
        $(".page_content").css("line-height", textLineHeight + "px");
        $(".page_content").css("text-indent", textIndent + "px");
        $("#fontup").click(function() {
            if (textFontSize >= 32) {
                textFontSize = 32;
                titleFontSize = 34;
                textLineHeight = 60;
                textIndent = 64;
            } else {
                textFontSize += 2;
                titleFontSize += 2;
                textLineHeight += 4;
                textIndent = 2 * textFontSize;
            }
            ;$(".page_content").css("font-size", textFontSize + "px");
            $(".page_title").css("font-size", titleFontSize + "px");
            $(".page_content").css("line-height", textLineHeight + "px");
            $(".page_content").css("text-indent", textIndent + "px");
            window.localStorage.setItem('textFontSize', textFontSize);
            window.localStorage.setItem('titleFontSize', titleFontSize);
            window.localStorage.setItem('textLineHeight', textLineHeight);
            window.localStorage.setItem('textIndent', textIndent);
        });
        $("#fontdown").click(function() {
            if (textFontSize <= 12) {
                textFontSize = 12;
                titleFontSize = 14;
                textLineHeight = 20;
                textIndent = 24;
            } else {
                textFontSize -= 2;
                titleFontSize -= 2;
                textLineHeight -= 4;
                textIndent = 2 * textFontSize;
            }
            ;$(".page_content").css("font-size", textFontSize + "px");
            $(".page_title").css("font-size", titleFontSize + "px");
            $(".page_content").css("line-height", textLineHeight + "px");
            $(".page_content").css("text-indent", textIndent + "px");
            window.localStorage.setItem('textFontSize', textFontSize);
            window.localStorage.setItem('titleFontSize', titleFontSize);
            window.localStorage.setItem('textLineHeight', textLineHeight);
            window.localStorage.setItem('textIndent', textIndent);
        });
        $(".page_content").click(function() {
            if ($(".header_2").hasClass("hidden")) {
                $(".header_2").removeClass("hidden");
                $(".controls_bot_bg ").removeClass("hidden");
                $(".top-alert .alert").addClass("alert_cont");
            } else {
                $(".header_2").addClass("hidden");
                $(".controls_bot_bg ").addClass("hidden");
                $(".font_setbox").addClass("hidden");
                $(".top-alert .alert").removeClass("alert_cont");
            }
        })
        $(".mask").click(function() {
            $('.mask').addClass('hidden');
            $('.giftbg').addClass('hidden');
            $('.gift_tips_box').addClass('hidden');
            $('.read_first').addClass('hidden');
        })
        $(".bot_btn .go_back").click(function() {
            $('.mask').addClass('hidden');
            $('.gift_tips_box').addClass('hidden');
        })
        $(".bot_btn .go_dashang").click(function() {
            $('.gift_tips_box').addClass('hidden');
            $('.giftbg').removeClass('hidden');
        })
        $(".read_first").click(function() {
            $('.mask').addClass('hidden');
            $('.read_first').addClass('hidden');
        })
        $(".read_cont").on("click", function() {
            $('.mask').removeClass('hidden');
            $('.read_cont_box').removeClass('hidden');
            ns.ModalHelper.afterOpen();
        });
        $('.mask').on("click", function() {
            ns.ModalHelper.beforeClose();
            $('.mask').addClass('hidden');
            $('.read_cont_box').addClass('hidden');
        });
        $(".read_gift").click(function() {
            ns.ModalHelper.afterOpen();
            $('.mask').removeClass('hidden');
            $('.giftbg').removeClass('hidden');
        })
        $(".close_gift_box").click(function() {
            ns.ModalHelper.beforeClose();
            $('.mask').addClass('hidden');
            $('.giftbg').addClass('hidden');
        })
        $(".write_comment").click(function() {
            ns.ModalHelper.afterOpen();
            $('.mask').removeClass('hidden');
            $('.write_comment').removeClass('hidden');
        })
        $('.control_cent_tag').click(function() {
            if ($('.set_box').hasClass('hiden')) {
                $('.set_box').removeClass('hiden')
            } else {
                $('.set_box').addClass('hiden')
            }
            return
        });
    }
    ns.run();
}
)(bookReadPage);
function check_user_bind() {
    var res = true;
    var userid = parseInt($('#userid').val() || 0);
    if (userid == 0) {
        return true;
    }
    $.ajax({
        url: "/user-check_user_phone",
        async: false,
        success: function(e) {
            if (e == 1) {
                $("body").css('overflow', "auto");
                $("body").removeClass('top_distance');
                $(".tips_phone").addClass('hidden');
                $(".mask2").addClass('hidden');
                res = true;
            } else {
                $(".tips_phone").removeClass('hidden');
                $("body").addClass('top_distance');
                $(".mask2").removeClass('hidden');
                $("body").css('overflow', "hidden");
                res = false;
            }
        }
    });
    return res;
}
;;var bookPage = _ns.genNameSpace("ns.bookPage");
(function(ns) {
    ns.run = function() {
        ns.pageInit();
        ns.bindComment();
        ns.bindRecommend();
    }
    ns.pageInit = function() {
        ns.articleUserid = parseInt($('#article_userid').val());
        ns.articleId = parseInt($('#article_id').val() || 0);
        ns.userId = parseInt($('#userid').val() || 0);
    }
    ns.bindRecommend = function() {
        $('.recommend-btn').click(function(e) {
            var btn = $(this);
            var articleid = ns.articleId;
            var score = parseInt($('.fans_zan_num').html());
            $.ajax({
                url: _util.config.url.dynamic + "/recommend-recommend_book",
                data: {
                    articleid: articleid,
                    source: 'wap'
                },
                dataType: "jsonp",
                success: function(e) {
                    if (e.status == 200) {
                        $('.fans_zan_num').html(score + 1);
                        alertMsg(e.msg);
                    } else if (e.status == 301) {
                        location.href = e.msg;
                        return false;
                    } else {
                        alertMsg(e.msg);
                    }
                }
            });
        })
    }
    ns.bindComment = function() {
        var showCommentBox = function() {
            if (!ns.userId) {
                _util.notLogin();
                return false;
            }
            var btn = $(this);
            var reply_id = parseInt(btn.attr('data-repid'));
            var submitBtn = $('.comment_bottom .index-commit-submit');
            var inputArea = $('.comment_bottom textarea');
            var pid = parseInt(btn.attr('data-pid') || 0);
            var name = btn.attr('data-name') || '';
            if (isNaN(reply_id))
                $('.reply_id').val('');
            $('.reply_pid').val(reply_id);
            name = name.replace(/(^\s+)|(\s+$)/g, "");
            var sendUserID = btn.attr('data-sendUserID')
            if (typeof (sendUserID) != 'undefined') {
                submitBtn.attr('data-sendUserID', sendUserID);
            } else {
                console.log(submitBtn.attr('data-sendUserID'))
                submitBtn.attr('data-sendUserID', ns.articleUserid);
            }
            if (name != "") {
                inputArea.val('@' + name + ':');
            } else {
                inputArea.val('');
            }
            submitBtn.attr('data-pid', pid);
            $('.mask').removeClass('hidden');
            $('.comment_bottom').removeClass('hidden');
        }
        $('.comment_2_dd').click(showCommentBox)
        $(".write_comment").click(showCommentBox)
        var submitCommmentFunc = function(event) {
            var btn = $(this);
            var pid = parseInt(btn.attr('data-pid') || 0);
            var userid = ns.userId;
            var articleid = ns.articleId;
            var content = $('.comment_bottom textarea').val();
            var money = $(this).siblings('.give_anyemoney').find('.btn_num').val();
            var reply_id = $('.reply_pid').val();
            var re = /^[1-9]+[0-9]*]*$/;
            if (money != 0) {
                if (!re.test(money)) {
                    _util.alert("请输入正确金额");
                    return false;
                }
                if (!check_user_bind()) {
                    return false;
                }
            }
            if (isNaN(reply_id))
                reply_id = '';
            $('.reply_pid').val(reply_id);
            var sendUserID = parseInt(btn.attr('data-sendUserID') || 0)
            if (!btn.hasClass('act'))
                return false;
            if (!ns.userId) {
                _util.notLogin();
                return false;
            }
            $('.comment_bottom .index-commit-submit').unbind('click');
            $.ajax({
                url: _util.config.url.dynamic + "/comment-comment",
                data: {
                    articleid: articleid,
                    message: content,
                    pid: pid,
                    touserid: userid,
                    money: money,
                    reply_pid: reply_id,
                    sendUserID: sendUserID
                },
                dataType: "jsonp",
                success: function(res) {
                    if (res.status == 200) {
                        if (res.msg != '')
                            alert(res.msg)
                        location.reload()
                    } else {
                        if (res.msg != '')
                            alert(res.msg)
                    }
                },
                error: function(e) {
                    $('.comment_bottom .index-commit-submit').click(submitCommmentFunc);
                }
            });
        };
        $('.comment_bottom .index-commit-submit').click(submitCommmentFunc);
        $('.comment_bottom textarea').keyup(function() {
            if ($('.comment_bottom textarea').val() == '') {
                $('.index-commit-submit').removeClass('act');
            } else {
                $('.index-commit-submit').addClass('act');
            }
        })
        $(".mask").click(function() {
            $('.mask').addClass('hidden');
            $('.giftbg').addClass('hidden');
            $('.comment_bottom').addClass('hidden');
        })
    }
    ns.run();
}
)(bookPage);
$(function() {
    $('.btn_subtract').click(function() {
        var numbox = $(this).parent('.give_anyemoney').find('.btn_num');
        var num = parseInt(numbox.val());
        if (numbox.val().length == 0) {
            num = 20;
        }
        num = num - 10;
        if (num < 0) {
            num = 0;
        }
        numbox.val(num);
    })
})
$(function() {
    $('.btn_add').click(function() {
        var numbox = $(this).parent('.give_anyemoney').find('.btn_num');
        var num = parseInt(numbox.val());
        if (numbox.val().length == 0) {
            num = 0;
        }
        num = num + 10;
        if (num > 100) {
            num = num + 40;
        }
        numbox.val(num);
    })
})
function alertMsg(msg) {
    $('.tips_alert').removeClass('hidden');
    $('.tips_alert').html(msg);
    setTimeout(function(aa) {
        $('.tips_alert').addClass('hidden');
    }, 2000);
}
;;var collection = {
    DayTime: ""
}
collection.init = function() {
    this.bindColl();
    this.collFun();
}
;
collection.bindColl = function() {
    var self = this;
    $('.top-alert .close').on("click", function() {
        $('.top-alert').addClass('hidden');
        self.timeFun();
        var dayTime = self.DayTime;
        var article_id = $("#article_id").val();
        var storid = JSON.parse(localStorage.getItem('articleId'));
        storid[article_id] = dayTime;
        localStorage.setItem("articleId", JSON.stringify(storid));
        $('.top-alert').addClass('hidden');
    })
}
;
collection.timeFun = function() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    this.DayTime = year + "-" + month + "-" + day;
}
;
collection.collFun = function() {
    this.timeFun();
    var StorarticleId = localStorage.getItem('articleId');
    if (!StorarticleId) {
        localStorage.setItem("articleId", '{}');
        StorarticleId = {};
    } else {
        StorarticleId = JSON.parse(localStorage.getItem('articleId'));
    }
    var article_id = $("#article_id").val();
    if (StorarticleId[article_id]) {
        var stortime = StorarticleId[article_id];
        if (this.DayTime == StorarticleId[article_id]) {
            $('.top-alert').addClass('hidden');
        }
    }
}
$(function() {
    collection.init();
});
